<template>
	<div style="background-color: #ffff7f;">
		<van-nav-bar title="上新车辆" left-text="返回" left-arrow @click-left="onClickLeft" />
		<div>
			<p style="margin: 8px 0px; font-weight: bolder;">车辆基本信息</p>
			<van-form @submit="onSubmit">
				<van-field v-model="brand" name="brand" label="品牌" placeholder="请输入品牌,如: 丰田" clearable />
				<van-field v-model="series" name=series label="系列" placeholder="请输入系列,如: 卡罗拉" clearable />
				<van-field v-model="years" name="years" label="款待" placeholder="请输入款待,如: 2018款" clearable />
				<van-field v-model="gearBox" name="gearBox" label="变速箱" placeholder="请输入变速箱,如: 自动" clearable />
				<van-field v-model="engine" name="engine" label="发动机" placeholder="请输入发动机,如: 1.2T" clearable />
				<van-field v-model="edition" name="edition" label="版本" placeholder="请输入版本,如: 智辉版" clearable />
				<van-field v-model="licensingTime" name="licensingTime" label="上牌时间" placeholder="请输入上牌时间,如: 2018年9月" clearable />
				<van-field v-model="tableMileage" name="tableMileage" label="表显里程" placeholder="请输入表显里程,如: 1.10万公里" clearable />
				<van-field v-model="color" name="color" label="颜色" placeholder="请输入颜色,如: 白色" clearable />
				<van-field v-model="environmentalStandards" name="environmentalStandards" label="环保标准" placeholder="请输入环保标准,如: 国六"
				 clearable />
				<van-field v-model="totalPrice" name="totalPrice" label="总价" placeholder="请输入总价,如: 12.40万" clearable />
				<van-field v-model="downPayment" name="downPayment" label="首付价" placeholder="请输入首付价,如: 2.00万" clearable />
				<p style="margin: 8px 0px; font-weight: bolder;">其他信息</p>
				<van-field v-model="notes" name="notes" label="说明或备注" type="textarea" placeholder="请输入其他说明或备注" />
				<van-button round block type="info" native-type="submit">提交</van-button>
			</van-form>
		</div>
	</div>
</template>

<script>
	import {
		Notify,
		Dialog
	} from 'vant';

	export default {
		data() {
			return {
				user: {},
				shopId: "",
				brand: "",
				series: "",
				years: "",
				gearBox: "",
				engine: "",
				edition: "",
				licensingTime: "",
				tableMileage: "",
				color: "",
				environmentalStandards: "",
				totalPrice: "",
				downPayment: "",
				notes: "",
				carData: null
			}
		},
		methods: {
			onClickLeft() {
				this.$router.back()
			},
			onSubmit(values) {
				this.$axios({
					method: 'post',
					url: '/carshop/saveCar',
					headers: {
						'UserId': this.user.userId,
						'CarToken': this.user.token
					},
					data: this.$qs.stringify({
						shopId: this.shopId,
						brand: values.brand,
						series: values.series,
						years: values.years,
						gearBox: values.gearBox,
						engine: values.engine,
						edition: values.edition,
						licensingTime: values.licensingTime,
						tableMileage: values.tableMileage,
						color: values.color,
						environmentalStandards: values.environmentalStandards,
						totalPrice: values.totalPrice,
						downPayment: values.downPayment,
						notes: values.notes
					})
				}).then((resp) => {
					if (resp.data.status == 200) {
						Notify({
							type: 'success',
							message: '添加汽车成功'
						});
						this.$router.push({
							path: "/shop/addcarimg",
							query: {
								carId: resp.data.obj
							}
						})
					} else {
						Dialog.alert({
							message: '添加汽车失败',
						})
					}
				})

			}
		},
		mounted() {
			let user = this.$cookies.get('user');
			if (user != null) {
				this.user = user;
				this.shopId = user.shopId;
			} else {
				Notify({
					type: 'danger',
					message: '未登录或登录已失效，请重新登录'
				})
				this.$router.back()
			}

		}
	}
</script>

<style scoped>
</style>
